package interceptcrossing.ui.command;

import interceptcrossing.Intercept;
import interceptcrossing.command.Command;
import interceptcrossing.ui.MainWindowDirector;

import java.util.HashSet;
import java.util.Set;

public class RemoveAllInterceptsCommand implements Command {

	private MainWindowDirector windowDirector;
	private Set<Intercept> intercepts = new HashSet<Intercept>();

	public RemoveAllInterceptsCommand(MainWindowDirector windowDirector) {
		if (windowDirector == null) {
			throw new NullPointerException("Main window director cannot be null");
		}

		this.windowDirector = windowDirector;
	}

	public void doCommand() {
		this.intercepts.addAll(this.windowDirector.getIntercepts());
		this.windowDirector.clearIntercepts();
	}

	public String getDescription() {
		return "Удаление всех отрезков";
	}

	public void undoCommand() {
		for (Intercept intercept : intercepts) {
			this.windowDirector.addIntercept(intercept);
		}
	}

}
